package cn.mystylefree.gifdemo;

import com.madgag.gif.fmsware.AnimatedGifEncoder;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @program my-project-model
 * @description:
 * @author: lee
 * @create: 2022/09/15 15:52
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedImage image1 = ImageIO.read(new File(Main.class.getResource("/static/snow1.png").getFile()));
        BufferedImage image2 = ImageIO.read(new File(Main.class.getResource("/static/snow2.png").getFile()));
        BufferedImage image3 = ImageIO.read(new File(Main.class.getResource("/static/snow3.png").getFile()));
        BufferedImage image4 = ImageIO.read(new File(Main.class.getResource("/static/snow4.png").getFile()));
        BufferedImage image5 = ImageIO.read(new File(Main.class.getResource("/static/snow5.png").getFile()));
        AnimatedGifEncoder e = new AnimatedGifEncoder();
        e.setSize(700, 400);
        //生成的图片路径
        e.start(new FileOutputStream("/usr/local/software/work/idea/my-project-model/gif-demo/src/main/resources/static/test_gif.gif"));
        //图片之间间隔时间
        e.setDelay(500);
        //重复次数 0表示无限重复 默认不重复
        e.setRepeat(0);
        //添加图片
        e.addFrame(image1);
        e.addFrame(image2);
        e.addFrame(image3);
        e.addFrame(image4);
        e.addFrame(image5);
        e.finish();
    }
}
